#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <app.h>
……
//Android ブラウザ画面 表示
StreamString html = //StreamStringクラス
R"( //R
プレフィックスによるHTMLなどの文字列リテラル化
*********************************************************************************************************************
* <!DOCTYPE html> //以下、HTML、CSS、JavaScriptによる記述 *
* <html lang="ja"> *
* …… *
* <script> *
* …… *
* async function updateOutput(){ //Aruduino言語からデータ取得、outputタグの表示更新 *
* const output = document.getElementById("output"); *
* try { *
* const response = await fetch("/get/mode"); *
* if (response.ok)output.textContent = await response.text(); *
* else { throw new Error(); } *
* } catch (error) { console.log(error); } *
* } *
* …… *
* setInterval('ShowPage()', 100); //表示、100[msec]毎に更新 *
* </script> *
* *
* <button type="button" class="buttonA" onclick="location.href=' /myTouch'">Play/Pause</button> //<button>タグ *
* *
* …… *
* </html> //以上、 HTML、CSS、JavaScriptによる記述 *
*********************************************************************************************************************
)";
// サーバーリクエスト時処理関数
void handleRoot() {
server.send(200, "text/html", html); //レスポンス200を返し、htmlデータ送信
//server.send (レスポンスコード, "データ形式", 送信データ);
}
void TouchAndroid(){ //Android 画面 演奏/一時停止タッチ操作処理
if(PlayMode == 0)PlayMode = 1;
else PlayMode = 0;
handleRoot();
}
// ブラウザ表示更新:PlayMode //演奏/一時停止 他
void getMode(){
int SendData;
char buf[32];
AdValue12 = analogRead(VOLUME_PIN); //可変抵抗器AD値を読み出し
SendData = PlayMode * 1000000 //100万倍 ////PlayMode、ix、AdValue12データを加算した送信データを作成
+ ix * 10000 //1万倍
+ AdValue12;
sprintf(buf, "%d", SendData); // dataの値を文字列として格納
server.send(200, "text/html", buf); // レスポンス200を返し、dataを文字列で送信
}
……
void setup(void) {
server.on("/", handleRoot);//サーバー設定
//server.on(URIアドレス、関数名) //URIにアクセスがあった時に呼び出す関数を登録
server.on("/myTouch",TouchAndroid); //Android画面 Play/Pauseボタン操作 受信処理
server.on("/get/mode", getMode); // データ表示更新受信処理
……
}
void loop(void) {
server.handleClient(); //登録した情報に従ってクライアントからのリクエストを処理する関数
……
}